home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-13 | 5.6 KB | 231 lines | [TEXT/CWIE] |
- /*
- File: ScrapPickerUtils.c
- Copyright: © 1997 by Apple Computer, Inc., all rights reserved.
- */
-
-
- //===============================================================================
- //
- // ScrapPickerUtils.c
- //
- //===============================================================================
-
-
-
- #include <TextUtils.h> // <-- Public interfaces.
- #include "ScrapPicker.h" // <-- Project interfaces.
- #include "PickerCommon.h"
-
-
- static void CheckMouseCursor (PickerStorageHandle);
-
-
- //===================================================================== Functions
- //--------------------------------------------------------------------- ActivatePicker
-
- void ActivatePicker (PickerStorageHandle storage)
- {
- (*storage)->active = true;
- }
-
- //--------------------------------------------------------------------- DeactivatePicker
-
- void DeactivatePicker (PickerStorageHandle storage)
- {
- (*storage)->active = false;
- }
-
- //--------------------------------------------------------------------- DoMouseDown
-
- OSErr DoMouseDown (PickerStorageHandle storage, EventData *data)
- {
- #pragma unused (storage, data)
-
- return noErr;
- }
-
- //--------------------------------------------------------------------- DoKeyDown
- // Mainly this function is used to intercept the keystrokes and Beep if
- // an illegal character is entered.
-
- OSErr DoKeyDown (PickerStorageHandle storage, EventData *data)
- {
- #pragma unused (storage, data)
-
- return noErr;
- }
-
- //--------------------------------------------------------------------- DoKeyUp
-
- OSErr DoKeyUp (PickerStorageHandle storage, EventData *data)
- {
- #pragma unused (storage, data)
-
- return noErr;
- }
-
- //--------------------------------------------------------------------- DoIdle
-
- OSErr DoIdle (PickerStorageHandle storage, EventData *data)
- {
- #pragma unused (data)
-
- CheckMouseCursor(storage);
-
- return noErr;
- }
-
- //--------------------------------------------------------------------- DoListClick
-
- OSErr DoListClick (PickerStorageHandle storage, ItemHitData *data)
- {
- Rect origColorRect;
- Boolean inBox;
- Boolean lastInBox;
- PMColor newTemp;
- Point where;
- PickerStoragePtr pStorage;
- OSErr theErr;
-
- theErr = noErr;
-
- GetItemRect(storage, iOrigColor, &origColorRect);
-
- inBox = true;
- lastInBox = false;
-
- pStorage = *storage;
-
- newTemp = pStorage->currPMColor;
-
- do
- {
- GetMouse(&where);
- inBox = PtInRect(where, &origColorRect);
- if (inBox != lastInBox)
- {
- lastInBox = inBox;
- if (inBox)
- pStorage->currPMColor = pStorage->origPMColor;
- else
- pStorage->currPMColor = newTemp;
-
- // Update the text.
- DrawColorEditor(storage, kDrawNew + kDrawProc);
- }
- }
- while (Button());
-
- if (inBox)
- {
- data->action = kColorChanged;
- pStorage->wasColor = newTemp;
- }
-
- return theErr;
- }
-
- //--------------------------------------------------------------------- PtInItem
-
- Boolean PtInItem (PickerStorageHandle storage, Point where, SInt16 itemNo)
- {
- Rect itemBounds;
-
- GetItemRect(storage, itemNo, &itemBounds);
-
- return (PtInRect(where, &itemBounds));
- }
-
- //--------------------------------------------------------------------- GetItemRect
- // Using the port in 'storage', this function returns the bounds of the
- // item requested.
-
- void GetItemRect (PickerStorageHandle storage, SInt16 itemNumber, Rect *itemBounds)
- {
- Handle itemHandle;
- SInt16 itemType;
-
- GetDialogItem((DialogPtr)((*storage)->port), (*storage)->baseItem + itemNumber,
- &itemType, &itemHandle, itemBounds);
- }
-
- //--------------------------------------------------------------------- GetItemHandle
- // Using the port in 'storage', this function returns a handle to the dialog
- // item requested.
-
- Handle GetItemHandle (PickerStorageHandle storage, SInt16 itemNumber)
- {
- Rect itemBounds;
- Handle itemHandle;
- SInt16 itemType;
-
- GetDialogItem((DialogPtr)((*storage)->port), (*storage)->baseItem + itemNumber,
- &itemType, &itemHandle, &itemBounds);
- check(itemHandle != 0L);
-
- return itemHandle;
- }
-
- //--------------------------------------------------------------------- SetColorPattern
- // Create a pattern to represent either the original or new color.
-
- void SetColorPattern (PickerStorageHandle storage, ColorType whichColor)
- {
- RGBColor rgb;
- PixPatHandle pat;
- PickerStoragePtr pStorage;
-
- pStorage = *storage;
-
- if (whichColor == kOriginalColor)
- {
- pat = pStorage->origColorPat;
- rgb = *(RGBColor *)&(pStorage->origPMColor.color).rgb;
- }
- else
- {
- pat = pStorage->newColorPat;
- rgb = *(RGBColor *)&(pStorage->currPMColor.color).rgb;
- }
-
- SetPatternToColor(pat, &rgb, pStorage->useColorPats);
- }
-
- //--------------------------------------------------------------------- SelectDeselectItemText
-
- void SelectDeselectItemText (PickerStorageHandle storage, SInt16 itemNo, Boolean selectIt)
- {
- PickerStoragePtr pStorage;
- GrafPtr thePort;
- SInt16 baseItem;
-
- pStorage = *storage;
- thePort = pStorage->port;
- baseItem = pStorage->baseItem;
-
- // If itemNo is zero we look at the editField in order to select the
- // current item. Otherwise we select the item number passed in.
- if (itemNo == 0)
- itemNo = ((DialogPeek)thePort)->editField + 1 - baseItem;
-
- if ((itemNo > 0) && (itemNo <= iLastItem))
- {
- if (selectIt)
- SelectDialogItemText(thePort, itemNo + baseItem, 0, 1024);
- else
- SelectDialogItemText(thePort, itemNo + baseItem, 0, 0);
- }
- }
-
- #pragma mark -------------------- Private Functions
- //===================================================================== Private Functions
- //--------------------------------------------------------------------- CheckMouseCursor
-
- static void CheckMouseCursor (PickerStorageHandle storage)
- {
- // If we're active (frontmost) and visible, update the cursor.
- if ((*storage)->active && (*storage)->visible)
- InitCursor();
- }
-
-